package com.whut.gkd.service.impl;

import com.whut.gkd.bean.ApplyManager;
import com.whut.gkd.bean.PageInfo;
import com.whut.gkd.dao.IApplyManagerDao;
import com.whut.gkd.service.IApplyManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApplyManagerServicelmpl implements IApplyManagerService {

    @Autowired
    private IApplyManagerDao applymanagerDao;

    @Override
    public PageInfo<ApplyManager> findAll(int currentPage, String applicanName) {
        PageInfo<ApplyManager> pageInfo= new PageInfo();

        int totalCount=applymanagerDao.getTotalCount(applicanName);
        pageInfo.setTotalCount(totalCount);
        double d=totalCount/5.0;
        int tp= (int) Math.ceil(d);
        pageInfo.setTotalPage(tp);
        pageInfo.setSize(5);
        if(currentPage<1){
            pageInfo.setCurrentPage(1);
        }else if(currentPage>tp){
            pageInfo.setCurrentPage(tp);
        }else {
            pageInfo.setCurrentPage(currentPage);
        }
        int start=(pageInfo.getCurrentPage()-1)*5;
        if(totalCount!=0){
        List<ApplyManager> managermanager= applymanagerDao.findAll(start,5,applicanName);
        pageInfo.setList(managermanager);
        }else{
            pageInfo.setList(null);
        }
        return pageInfo;
    }

    @Override
    public void allowmanagerByapplicanId(int applicanId){
        applymanagerDao.allowmanagerByapplicanId(applicanId);
    }

    @Override
    public void deleteByapplicanId(int applicanId) {
        applymanagerDao.deleteByapplicanId(applicanId);
    }


}
